New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@axolo/tree-array

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@axolo/tree-array

An array have children key and parentId key like tree.

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

tree-array

An array have children key and parentId key like tree.

install

npm i @axolo/tree-array

usage

import { tree2array, array2tree } from '@axolo/tree-array'
const array = array2tree([/* array */])
const tree = tree2array([/* tree */])

api

functionreturndescription
array2tree(array, [options])treearray to tree
arrayDeep(array, [options], [deep = 1])intget max deep of array
arrayNode(array, id, [options])arrayget path of id from array by id, like [id1, id12, id121]
arrayParents(id, array, [options])arrayfind parents from array by id
tree2array(tree, [options])arraytree to array
treeDeep(tree, [options], [deep = 1])intget max deep of tree
treeNode(tree, id, [options])arrayget path of id from tree by id, like [id1, id12, id121]
treePath(tree, id, [options])arrayget path of index from tree by id, like [0, 2, 1]
treeSub(tree, id, [options])objectget sub tree by id, like { id, parentId, children: [] }

options

paramstypedefaultdescription
idKeystringidkey of id
parentKeystringparentIdkey of parentId
childrenKeystringchildrenkey of children
leafKeystringleafkey of leaf
leafValueanytruevalue of leaf
deepKeystringdeepkey of deep
deepValuenumber0value of deep

data

The data format MUST like example with key defined in options.

array

[{
  "id": "chart",
  "path": "/chart",
  "parentId": null
}, {
  "id": "chartIndex",
  "path": "/chart/index",
  "parentId": "chart"
}, {
  "id": "chartIndexActive",
  "path": "/chart/index/active",
  "parentId": "chartIndex"
}, {
  "id": "chartIndexActiveMy",
  "path": "/chart/index/active/my",
  "parentId": "chartIndexActive"
}, {
  "id": "chartReview",
  "path": "/chart/review",
  "parentId": "chart"
}, {
  "id": "chartProject",
  "path": "/chart/project",
  "parentId": "chart"
}, {
  "id": "smile",
  "path": "/smile",
  "parentId": null
}, {
  "id": "smileIndex",
  "path": "/smile/index",
  "query": "test",
  "parentId": "smile"
}]

tree

[{
  "id": "chart",
  "path": "/chart",
  "parentId": null,
  "children": [{
    "id": "chartIndex",
    "path": "/chart/index",
    "parentId": "chart",
    "children": [{
      "id": "chartIndexActive",
      "path": "/chart/index/active",
      "parentId": "chartIndex",
      "children": [{
        "id": "chartIndexActiveMy",
        "path": "/chart/index/active/my",
        "parentId": "chartIndexActive"
      }]
    }]
  }, {
    "id": "chartReview",
    "path": "/chart/review",
    "parentId": "chart"
  }, {
    "id": "chartProject",
    "path": "/chart/project",
    "parentId": "chart"
  }]
}, {
  "id": "smile",
  "path": "/smile",
  "parentId": null,
  "children": [{
    "id": "smileIndex",
    "path": "/smile/index",
    "query": "test",
    "parentId": "smile"
  }]
}]

Yueming Fang 2022-09-04

Keywords

FAQs

Package last updated on 21 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc